﻿using SD.Infrastructure.EntityBase;
using System;
using System.Text;

namespace SD.ContentSystem.Domain.Entities
{
    /// <summary>
    /// 消息
    /// </summary>
    public class Message : AggregateRootEntity
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected Message() { }
        #endregion

        #region 01.创建消息构造器
        /// <summary>
        /// 创建消息构造器
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <param name="contact">联系人</param>
        /// <param name="phoneNo">联系电话</param>
        /// <param name="email">电子邮箱</param>
        public Message(string title, string content, string contact, string phoneNo, string email)
            : this()
        {
            base.Name = title;
            this.Content = content;
            this.Contact = contact;
            this.PhoneNo = phoneNo;
            this.Email = email;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 内容 —— string Content
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; private set; }
        #endregion

        #region 联系人 —— string Contact
        /// <summary>
        /// 联系人
        /// </summary>
        public string Contact { get; private set; }
        #endregion

        #region 联系电话 —— string PhoneNo
        /// <summary>
        /// 联系电话
        /// </summary>
        public string PhoneNo { get; private set; }
        #endregion

        #region 电子邮箱 —— string Email
        /// <summary>
        /// 电子邮箱
        /// </summary>
        public string Email { get; private set; }
        #endregion

        #region 回复 —— string FeedBack
        /// <summary>
        /// 回复
        /// </summary>
        public string FeedBack { get; private set; }
        #endregion

        #region 回复人 —— string Replyer
        /// <summary>
        /// 回复人
        /// </summary>
        public string Replyer { get; private set; }
        #endregion

        #region 回复时间 —— DateTime? ReplyTime
        /// <summary>
        /// 回复时间
        /// </summary>
        public DateTime? ReplyTime { get; private set; }
        #endregion

        #endregion

        #region # 方法

        #region 回复 —— void Reply(string feedBack, string replyer)
        /// <summary>
        /// 回复
        /// </summary>
        /// <param name="feedBack">回复内容</param>
        /// <param name="replyer">回复人</param>
        public void Reply(string feedBack, string replyer)
        {
            this.FeedBack = feedBack;
            this.Replyer = replyer;
            this.ReplyTime = DateTime.Now;
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(this.Name);
            builder.Append(this.Content);
            builder.Append(this.Contact);
            builder.Append(this.PhoneNo);
            builder.Append(this.Email);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
